home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cobalts.arc
/
ANIMAKE.C
next >
Wrap
Text File
|
1990-09-03
|
4KB
|
157 lines
/* animake.c
by Bill Buckels 1990
revised to support virtual screens may 1990.
converts CGA COMPATIBLE .PCX files into a
C-LANGUAGE CHARACTER ARRAY HEADER OF THE SAME NAME
but having the extension ".c"
the graphic is embedded and either compiled seperately
as an object file and declared external & linked to
or alternately is used as a header.
the graphic is then unpacked directly into a screen buffer,
or alternately into the frame buffer without disk i/o.
with respect to bitching about compiler use to reorganize
binary image data into symbolic data that ends up in binary
format as an object file we should recognize that there are
many compiler specific formats (ie- .OBJ, .MIX, .O ) and each
compiler produces suitable OBJECT MODULES from a source file
and does not need to be supplemented with a FOLKSY HOMESPUN version.
*/
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <string.h>
unsigned int byteword(unsigned char a, unsigned char b){return b<<8|a;}
unsigned char pcxheader[128];
int imagewidth;
int imageheight;
int colorpcxsprite(char *name)
{
FILE *fp; /* reads a ZSOFT .PCX header */
int i; /* we only want CGA COLOR sprites */
unsigned int zsoft,codetype,pixbits;
unsigned int ymin, ymax;
int invalid = -1, valid = 0, status=valid;
/* read the file header */
if((fp=fopen(name,"rb"))==NULL)return -1;
for(i=0;i!=128;i++)pcxheader[i]=fgetc(fp);
fclose(fp);
zsoft =pcxheader[0];
codetype=pcxheader[2];
pixbits =pcxheader[3];
if(zsoft!=10) status = invalid;
if(codetype!=1) status = invalid;
if(pixbits != 2 )
if(pixbits!=1)
status = invalid;
ymin=byteword(pcxheader[6],pcxheader[7]);
ymax=byteword(pcxheader[10],pcxheader[11]);
imagewidth= byteword(pcxheader[66],pcxheader[67]);
imageheight=(ymax-ymin);
return status;
}
char separators[]=" .\n";
int PCXARRAY(char *pcxfilename)
{
unsigned int packet=16,width=0;
FILE *fp,*fp2;
long wordcount,target;
char buffer[128];
char name[128];
char name2[128];
char *wordptr;
strcpy(buffer,pcxfilename);
wordptr=strtok(buffer,separators);
strcpy(name,buffer);
strcat(name,".PCX");
strcpy(name2,buffer);
strcat(name2,".c");
if(colorpcxsprite(name)==-1)return-1;
fp = fopen(name,"rb");
fp2 = fopen(name2,"w");
printf("\nInput File : %s",name);
printf("\nOutput File: %s\n",name2);
target = filelength(fileno(fp));
for(wordcount=0;wordcount<128;wordcount++)fgetc(fp);
fprintf(fp2,
"/* Character Array of .PCX format Run Length Encoded CGA Graphic */\n");
fprintf(fp2,
"/* .PCX Input File Name was %s */\n\n",name);
fprintf(fp2,
"/* The Image Descriptor Integer Array precedes the Character Array.*/\n");
fprintf(fp2,
"/* Descriptor Fields are: 1. Length of Character Array. */\n");
fprintf(fp2,
"/* 2. Width of Graphic in BYTES. */\n");
fprintf(fp2,
"/* 3. Height of Graphic in BYTES.*/\n\n");
fprintf(fp2,"long int %s",buffer);
fprintf(fp2,"_SIZE[3]={ %ld , %d, %d };\n\n",
(target-128l),imagewidth,imageheight);
fprintf(fp2,"unsigned char far %s[%ldl]={\n",buffer,(target-128l));
do{
fprintf(fp2,"%3d",fgetc(fp));
wordcount++;
if(wordcount !=target)fprintf(fp2,", ");
else fprintf(fp2,"};");
if(width++==packet){fprintf(fp2,"\n");
width=0;}
}while(wordcount!=target);
fclose(fp);
fclose(fp2);
return(0);
}
char *usage[]={
"Animake(C) Copyright by Bill Buckels 1990\n",
"is not a valid CGA color .PCX file.\n",
"Usage is \"ANIMAKE [PCXFILENAME]\"\n",
"Done!\n"};
main(int argc,char *argv[])
{
printf("%s",usage[0]);
switch (argc)
{
case 2: if(PCXARRAY(argv[1])==0)break;
printf("%s %s",argv[1],usage[1]);
default: printf("%s",usage[2]);
exit(0);
}
printf("%s",usage[3]);
exit(0);
}